<template>
  <div id="newsDetail">
    <div class="newsDetailTitleImg" v-show="!sceneType">
      <img src="../../assets/img/home/titleImgBack.png" alt="">
    </div>
    <div class="newsDetailContent">
      <div class="worksDetailNavInfo">
        <div v-show="!sceneType"><p @click="jumpTo('/home')">首页</p><span>&gt;</span><p>新闻公告</p></div>
        <div v-show="sceneType === 'megagame'"><p @click="jumpTo('/megagame')">技能大赛</p><span>&gt;</span><p>大赛新闻详情</p></div>
        <div v-show="sceneType === 'studioNews'"><p @click="jumpTo('/megagame')">技能大赛</p><span>&gt;</span><p @click="goBack()">师徒制工作室详情</p><span>&gt;</span><p>信息公告详情</p></div>
        <div v-show="sceneType === 'infoBulletin'"><p @click="jumpTo('/megagame')">技能大赛</p><span>&gt;</span><p @click="goBack()">大赛工作室详情</p><span>&gt;</span><p>信息公告详情</p></div>
        <div v-show="sceneType === 'obtainJob'"><p @click="jumpTo('/recruiting')">就业信息</p><span>&gt;</span><p>就业资讯详情</p></div>
<!--        <div v-show="sceneType === 'excellentProduct'"><p>校企合作</p><span>&gt;</span><p>创新创业优品汇</p></div>-->
      </div>
      <div class="newsDetailHtml">
        <h2>{{newsDetailData.title}}</h2>
        <div v-html="newsDetailData.content"></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'newsDetail',
  data () {
    return {
      sceneType: this.$route.query.sceneType,
      studioNewsId: this.$route.query.id,
      // studioNewsData: {},
      megagameNewsId: this.$route.query.megagameNewsId,
      // megagameNewsData: {},
      obtainJobNewsId: this.$route.query.obtainJobNewsId,
      // obtainJobNewsData: {},
      excellentProductId: this.$route.query.excellentProductId,
      // excellentProductData: {},
      dreamWorksId: this.$route.query.dreamWorksId,
      // dreamWorksData: {},
      angellId: this.$route.query.angellId,
      // angellData: {},
      createCourseId: this.$route.query.createCourseId,
      // createCourseData: {},
      newsDetailData: {}
    }
  },
  created () {
    if (!this.sceneType) {
      this.fetchNewsById()
    } else if (this.sceneType === 'megagame') {
      this.fetchNewsById()
    } else if (this.sceneType === 'studioNews') {
      this.fetchOneNews()
    } else if (this.sceneType === 'infoBulletin') {

    } else if (this.sceneType === 'obtainJob') {
      this.fetchgetOneJobNews()
    } else if (this.sceneType === 'excellentProduct') {
      this.fetchOneGoods()
    } else if (this.sceneType === 'dreamWorks') {
      this.fetchOneDreamFactory()
    } else if (this.sceneType === 'angell') {
      this.fetchOneTroupe()
    } else if (this.sceneType === 'createCourse') {
      this.fetchOneCurriculum()
    }
  },
  methods: {
    // 获取信息公告详情
    fetchOneNews () {
      this.$api.getOneNews({
        id: this.studioNewsId
      }).then(res => {
        // this.studioNewsData = res.data
        this.newsDetailData = {
          title: res.data.title,
          content: res.data.content
        }
      })
    },
    // 获取大赛新闻详情
    fetchNewsById () {
      this.$api.getNewsById({
        id: this.megagameNewsId
      }).then(res => {
        if (res.code === 0) {
          // this.megagameNewsData = res.data
          this.newsDetailData = {
            title: res.data.newsTitle,
            content: res.data.content
          }
        }
      })
    },
    // 获取就业资讯详情
    fetchgetOneJobNews () {
      this.$api.getOneJobNews({
        id: this.obtainJobNewsId
      }).then(res => {
        if (res.code === 0) {
          // this.obtainJobNewsData = res.data
          this.newsDetailData = {
            title: res.data.title,
            content: res.data.introduce
          }
        }
      })
    },
    // 获取优品汇详情
    fetchOneGoods () {
      this.$api.getOneGoods({
        id: this.excellentProductId
      }).then(res => {
        // this.excellentProductData = res.data
        this.newsDetailData = {
          title: res.data.title,
          content: res.data.content
        }
      })
    },
    // 获取梦工厂的详情
    fetchOneDreamFactory () {
      this.$api.getOneDreamFactory({
        id: this.dreamWorksId
      }).then(res => {
        if (res.code === 0) {
          this.newsDetailData = {
            title: res.data.factoryName,
            content: res.data.content
          }
        }
      })
    },
    // 获取创业天使团详情
    fetchOneTroupe () {
      this.$api.getOneTroupe({
        id: this.angellId
      }).then(res => {
        if (res.code === 0) {
          this.newsDetailData = {
            title: res.data.troupeName,
            content: res.data.content
          }
        }
      })
    },
    // 获取创业课程详情
    fetchOneCurriculum () {
      this.$api.getOneCurriculum({
        id: this.createCourseId
      }).then(res => {
        if (res.code === 0) {
          this.newsDetailData = {
            title: res.data.name,
            content: res.data.content
          }
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
#newsDetail{
  /deep/ img{
    width: 100%;
  }
  .newsDetailTitleImg{
    width: 100%;
    img{
      width: 100%;
    }
  }
  .newsDetailContent{
    width: 1200px;
    margin: auto;
    padding: .2rem 0;
  }
  .newsDetailHtml{
    padding: .2rem;
    background-color: #fff;
    h2 {
      text-align: center;
      font-size: .32rem;
      line-height: .48rem;
      font-weight: 500;
      color: #333;
      margin-bottom: .5rem;
    }
  }
}
</style>
